import {CURRENT_TOKEN} from "@/components/Authorized/renderAuthorize";
import request from "@/utils/request";
import URLS from "./APIUrlDefine";


export async function GetStatCourse(data: any): Promise<any> {
  return request(`${URLS.STAT_COURSE_DATA}/${data.current}/${data.pageSize}?id=${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  });
}


export async function GetStatExp(data: any): Promise<any> {
  return request(`${URLS.STAT_EXP_DATA}/${data.current}/${data.pageSize}?id=${data.id || -1}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  })
}


export async function GetStatExam(data: any): Promise<any> {
  return request(`${URLS.STAT_EXAM_DATA}/${data.current}/${data.pageSize}?course=${data.id || -1}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  });
}

/* 导出实验记录为excel*/
export async function PostExportExpStat(data: any): Promise<any> {
  return request(`${URLS.STAT_EXPORT_RECORDS}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data
  }).then((response) => {
    return Promise.resolve(response);
  }).catch(e => {
    console.error(e)
  });
}

export async function GetStatStudent(data: any): Promise<any> {
  return request(`${URLS.STAT_STUDENT_DATA}/${data.current}/${data.pageSize}?course=${data.id || -1}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  });
}
